/**
 * @(#)Workbook.java Created: 2009-10-29
 *
 * Copyright 2009 Zeus Medicine Group (ZS)
 * All rights reserved.
 *
 */

package nc.ui.zzjs.pub.excel;

import com.jacob.com.Dispatch;
import com.jacob.com.Variant;

/**Class - Workbook.java
*
* @version 1.0
* @date 2009-10-29
* @author smile
*
**/
public class Workbook {
	private Dispatch book = null;
	
	public String fileName = null;
	
	public Workbook(Dispatch book) {
		this.book = book;
		if (book != null) {
			fileName = getFileName();
		}
	}
	
	public Dispatch getDispatch() {
		return book;
	}
	
	public String getName() {
		Variant v = Dispatch.get(book, "Name");
		return v.getString();
	}
	
	public String getFileName() {
		Variant v = Dispatch.get(book, "FullName");
		return v.getString();
	}
	
	public void activate() {
		Dispatch.call(book, "Activate");
	}
	
	public Sheet getActiveSheet() {
		Variant v = Dispatch.get(book, "ActiveSheet");
		Dispatch t = v.toDispatch();
		return new Sheet(t);
	}
	
	//不保存修改，直接关闭
	public void close() {
		Dispatch.call(book, "Close", new Variant(false));
	}
	
	public void close(boolean saveChanges, String fileName) {
		Dispatch.call(book, "Close", new Variant(saveChanges), new Variant(fileName));
	}
	
	public void save() {
		Dispatch.call(book, "Save");
		//saveAs(fileName);
	}

	public void saveAs(String fileName) {
		Dispatch.call(book, "SaveAs", new Variant(fileName));
	}
	
	public Sheets getSheets() {
		Variant v = Dispatch.get(book, "Sheets");
		Dispatch t = v.toDispatch();
		return new Sheets(t);
	}
	
	public Sheets getWorksheets() {
		Variant v = Dispatch.get(book, "Worksheets");
		Dispatch t = v.toDispatch();
		return new Sheets(t);
	}
}
